//****************************************************
// Porman Project 
// Filename: CRenderViewport.h
// Date: 2011/01/15
// Author: KengYu Lin
// Modify:
//****************************************************
#ifndef _CRENDERVIEWPORT_H
#define _CRENDERVIEWPORT_H
#include <string>
#include "CRSDef.h"
#include "CRenderBase.h"

namespace Porman
{

namespace RS
{

class CRenderCamera;
class CRenderTarget;

class CRenderViewportData 
{
public:
    CRenderViewportData( void ) : 
    m_fOffsetX(0.0f), 
    m_fOffsetY(0.0f),
    m_fWidth(1.0f),
    m_fHeight(1.0f),
    m_fDepth(1.0f),   
    m_iStencil(0),
    m_pCamera(NULL)
    {
        float fColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
        memcpy( m_fColor, fColor, sizeof(float)*4 );
    }
    CRenderViewportData( const CRenderViewportData& l ) { (*this) = l; }
    CRenderViewportData& operator=( const CRenderViewportData& l )
    {
        m_fOffsetX = l.m_fOffsetX;
        m_fOffsetY = l.m_fOffsetY;
        m_fWidth = l.m_fWidth;
        m_fHeight = l.m_fHeight;

        memcpy( m_fColor, l.m_fColor, sizeof(float)*4 );
        m_fDepth = l.m_fDepth;
        m_iStencil = l.m_iStencil;

        m_pCamera = l.m_pCamera;
    }   

    float m_fOffsetX;
    float m_fOffsetY;
    float m_fWidth;
    float m_fHeight;
    float m_fColor[4];
    float m_fDepth;
    int m_iStencil;

    CRenderCamera* m_pCamera;
};

class CRenderViewport : public CRenderBase
{
public:
    CRenderViewport( const std::string& sName, unsigned int uiHash );
    virtual ~CRenderViewport( void );

    PRS_API void initial( CRenderTarget* pRT, CRenderCamera* pCamera, int iZOrder, float fOffsetX, float fOffsetY, float fWidth, float fHeight );
    PRS_API int getZOrder( void ) { return m_iZOrder; }

    PRS_API void setBackgroundColor( float fColor[4] );
    PRS_API void getBackgroundColor( float fColor[4] );
    PRS_API void setDepth( float fDepth );
    PRS_API float getDepth( void );
    PRS_API void setStencil( int iStencil );
    PRS_API int getStencil( void );

    PRS_API void setActualMertics( int iOffsetX, int iOffsetY, int iWidth, int iHeight );
    PRS_API void getActualMertics( int& iOffsetX, int& iOffsetY, int& iWidth, int& iHeight );
    PRS_API void setActualOffsetX( int iOffsetX );
    PRS_API int getActualOffsetX( void );
    PRS_API void setAcutalOffsetY( int iOffsetY );
    PRS_API int getActualOffsetY( void );
    PRS_API void setActualWidth( int iWidth );
    PRS_API int getActualWidth( void );
    PRS_API void setActualHeight( int iHeight );
    PRS_API int getActualHeight( void );

    PRS_API void setMertics( float fOffsetX, float fOffsetY, float fWidth, float fHeight );
    PRS_API void getMertics( float& fOffsetX, float& fOffsetY, float& fWidth, float& fHeight );
    PRS_API void setOffsetX( float fOffsetX );
    PRS_API float getOffsetX( void );
    PRS_API void setAcutalOffsetY( float fOffsetY );
    PRS_API float getOffsetY( void );
    PRS_API void setWidth( float fWidth );
    PRS_API float getWidth( void );
    PRS_API void setHeight( float fHeight );
    PRS_API float getHeight( void );

    PRS_API void setCamrea( CRenderCamera* pCamera ) { m_hViewportData.getData().m_pCamera = pCamera; }
    PRS_API CRenderCamera* getCamera( void ) { return m_hViewportData.getData().m_pCamera; }

    virtual void onSwap( void ); //Sync region will call this member function to switch data.
    virtual void onRender( void ); //Rendering thread will call this member function to perform rendering.

protected:
    CRenderTarget* m_pRT;
    CDataHandlerT<CRenderViewportData> m_hViewportData;
    int m_iZOrder;
};

}//End namespace RS

}//End namespace Porman


#endif